package com.wly.mina.filter;

import java.nio.ByteBuffer;
import java.util.logging.Logger;

import javassist.bytecode.ByteArray;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

import com.wly.gpb.Login.LogIn;
import com.wly.packet.CSLoginPacket;
import com.wly.packet.Packet;

public class GPBEncoder implements ProtocolEncoder
{
	Logger log = Logger.getLogger("GPBEncoder");
	@Override
	public void dispose(IoSession arg0) throws Exception
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void encode(IoSession session, Object msg, ProtocolEncoderOutput out)
			throws Exception
	{
		// TODO Auto-generated method stub
		log.info("encoder write message"+msg.toString());
		if(msg instanceof Packet)
		{
			out.write(((Packet) msg).serialization());
//			return;
		}
//		
//		IoBuffer buff = IoBuffer.allocate(128).setAutoExpand(true);
//		buff.putShort((short)12);
//		buff.putShort((short)3);
//		buff.flip();
//		out.write(buff);
		//out.write(msg);
	//	log.info("not a packet");
	}

}
